package com.h3c.nem.controller;

import com.eos.common.constant.StatusCodeEnum;
import com.eos.common.util.Result;
import com.h3c.nem.dto.FamilyAndContactorDTO;
import com.h3c.nem.service.ITbOfferFamilyService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 家庭成员控制层
 *
 * @author chenyifan
 * @since 2022-06-02 17:50:01
 */
@Slf4j
@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/tbOfferFamily")
public class TbOfferFamilyController {
    /**
     * 服务对象
     */
    private final ITbOfferFamilyService tbOfferFamilyService;

    /**
     * 保存家庭信息和紧急联系人
     * @param familyAndContactorDTO
     * @return
     */
    @PostMapping("/saveFamilyInfo")
    public Result<String> saveFamilyInfo(@RequestBody FamilyAndContactorDTO familyAndContactorDTO){
        try {
            tbOfferFamilyService.saveFamilyInfo(familyAndContactorDTO);
            return new Result(true, StatusCodeEnum.NORMAL);
        } catch (Exception e) {
            log.error(e.getMessage());
            return new Result(false, StatusCodeEnum.ADD_FAIl);
        }
    }

    /**
     * 回显家庭信息
     * @return
     */
    @GetMapping("/showFamilyInfo")
    public Result<String> showFamilyInfo(){
        try {
            return new Result(true, StatusCodeEnum.NORMAL,tbOfferFamilyService.showFamilyInfo());
        } catch (Exception e) {
            log.error(e.getMessage());
            return new Result(false, StatusCodeEnum.ADD_FAIl);
        }
    }
}

